﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Domotica.Media;
using Domotica.Windows.Controls;

namespace Domotica.Media
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class MainWindow : GazeWindow
    {
        private MediaPlayer _Player;

        public MainWindow()
        {
            InitializeComponent();
        }

        private void CommandNextTrack(object sender, ExecutedRoutedEventArgs e)
        {
            if ((RuntimeHelpers.GetObjectValue(this.lbxAlbums.SelectedItem)) != null)
            {
                this._Player.NextTrack();
                e.Handled = true;
            }
        }

        private void CommandPlay(object sender, ExecutedRoutedEventArgs e)
        {
            if (this.lbxAlbums.SelectedItem != null)
            {
                this._Player.Play((Album)this.lbxAlbums.SelectedItem);
                e.Handled = true;
            }
        }

        private void CommandPreviousTrack(object sender, ExecutedRoutedEventArgs e)
        {
            if (this.lbxAlbums.SelectedItem != null)
            {
                this._Player.PreviousTrack();
                e.Handled = true;
            }
        }

        private void CommandStop(object sender, ExecutedRoutedEventArgs e)
        {
            if (this.lbxAlbums.SelectedItem != null)
            {
                this._Player.Stop();
                e.Handled = true;
            }
        }

        private void LoadMusic()
        {
            this.MainPanel.DataContext = this._Player;
        }

        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);
            this._Player = new MediaPlayer();
            this.LoadMusic();
        }


    }
}
